import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { Cache } from "../../cache/Cache";
import { DateUtil } from "../../../common/tools/DateUtil";
import { ClockManager } from "../../manager/ClockManager";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { SecTimerView } from "../common/SecTimerView";
import { GangFightsMagicStoneWindow } from "./GangFightsMagicStoneWindow";
import { GangFightsMeritWindow } from "./GangFightsMeritWindow";
import { AIManager } from "../../scene/ai/AIManager";
import { ENpcEffect } from "../../../../Message/Public/ENpcEffect";
import { TitleItem } from "../common/item/TitleItem";
import { ObjTeamCreate } from "../common/ObjTeamCreate";
import { TilePanel } from "../equipment/TilePanel";
import { GangFightsBattleCellRenderer } from "./cellRenderer/GangFightsBattleCellRenderer";
import { SGangFightsMyInfo } from "../../../../Message/Public/SGangFightsMyInfo";
import { SGangFightsMyInfoEx } from "../../../../Message/Public/SGangFightsMyInfoEx";
import { SGangFightsBattles } from "../../../../Message/Public/SGangFightsBattles";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { SGangFightsSignUp } from "../../../../Message/Public/SGangFightsSignUp";
import { LineBox } from "../guide/LineBox";
import { EffectManager } from "../../manager/EffectManager";
import { GButton } from "../../../../com/mui/controls/GButton";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
//class GangFightsMainPanel
    
    export  class GangFightsMainPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.init();
            this.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddToStage);
            return;
        }

        /* internal  */onAddToStage(arg1: Object /* flash.events.Event */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GangFightsGetMyInfo));
            Dispatcher.dispatchEvent(new DataEvent(EventName.GangFightsGetBattles));
            if (Cache.instance.gangFights.myInfoEx) 
            {
                this._infoEx = Cache.instance.gangFights.myInfoEx;
                this.updateMoeny();
            }
            return;
        }

        public updateLastMoney(): void
        {
            var loc2=null;
            var loc3=null;
            var loc1=Cache.instance.gangFights.account;
            if (loc1) 
            {
                loc2 = loc1.dayAccountDt;
                loc3 = loc1.monthAccountDt;
                if (DateUtil.isSameDay(loc2, ClockManager.instance.nowDate)) 
                {
                    this._tfLastBeans.text = Language.getString(44504);
                }
                else if (this._infoEx) 
                {
                    this._tfLastBeans.text = Language.getStringByParam(44495, this._infoEx.lastMagicStone.toString());
                }
                if (DateUtil.isSameDay(loc3, ClockManager.instance.nowDate)) 
                {
                    if (loc1.monthAccountIndex != 4) 
                    {
                        this._tfLastMerit.text = Language.getString(44505);
                    }
                    else 
                    {
                        this._tfLastMerit.text = Language.getString(44592);
                    }
                }
                else if (this._infoEx) 
                {
                    this._tfLastMerit.text = Language.getStringByParam(44498, this._infoEx.lastMerit.toString());
                }
                return;
            }
            if (this._infoEx) 
            {
                this._tfLastBeans.text = Language.getStringByParam(44495, this._infoEx.lastMagicStone.toString());
                this._tfLastMerit.text = Language.getStringByParam(44498, this._infoEx.lastMerit.toString());
            }
            return;
        }

        /* internal  */init(): void
        {
            this.createLeftPart();
            this.createRightPart();
            this.updateMoeny();
            return;
        }

        /* internal  */createLeftPart(): void
        {
            var loc2=null;
            ObjCreate.createBg(0, 0, 193, 483, this);
            var loc1=GlobalClass.getBitmap(ImagesConst.fairylandPattern);
            loc1.x = 2;
            loc1.y = 2;
            this.addChild(loc1);
            ObjCreate.createTextField(Language.getString(44480), 12, 5, 150, 20, this, GlobalStyle.textFormat6);
            this._spTeam = new Object /* flash.display.Sprite */();
            this._spTeam.x = 12;
            this._spTeam.y = 30;
            this._spTeam.visible = false;
            this.addChild(this._spTeam);
            this._tfName = ObjCreate.createTextField(Language.getString(44481), 0, 0, 160, 20, this._spTeam);
            this._tfScore = ObjCreate.createTextField(Language.getString(44482), 0, 22, 90, 20, this._spTeam);
            this._tfRank = ObjCreate.createTextField(Language.getString(44483), 90, 22, 90, 20, this._spTeam);
            this._tfWin = ObjCreate.createTextField(Language.getString(44484), 0, 44, 90, 20, this._spTeam);
            this._tfLose = ObjCreate.createTextField(Language.getString(44485), 90, 44, 90, 20, this._spTeam);
            this._tfWinPer = ObjCreate.createTextField(Language.getString(44486), 0, 66, 90, 20, this._spTeam);
            this._tfTotalNum = ObjCreate.createTextField(Language.getString(44487), 90, 66, 90, 20, this._spTeam);
            this._spNoTeam = new Object /* flash.display.Sprite */();
            this._spNoTeam.x = 12;
            this._spNoTeam.y = 30;
            this.addChild(this._spNoTeam);
            ObjCreate.createTextField(Language.getString(44488), 23, 24, 160, 20, this._spNoTeam, GlobalStyle.textFormatRed);
            this._btnAddTeam = ObjCreate.createGButton(Language.getString(44489), 58, 50, 70, 26, this._spNoTeam, "ButtonRed");
            this._btnAddTeam.addEventListener(flash.events.MouseEvent.CLICK, this.onClickAddTeam);
            ObjCreate.createBg(5, 122, 180, 2, this, "SplitLine");
            loc2 = GlobalClass.getBitmap(ImagesConst.fairylandPattern);
            loc2.x = 2;
            loc2.y = 126;
            this.addChild(loc2);
            ObjCreate.createTextField(Language.getString(44490), 12, 130, 130, 20, this, GlobalStyle.textFormat6);
            this._tfSelfName = ObjCreate.createTextField(Language.getString(44481), 12, 158, 180, 20, this);
            this._tfSelfScore = ObjCreate.createTextField(Language.getString(44482), 12, 181, 180, 20, this);
            this._tfTodayNum = ObjCreate.createTextField(Language.getString(44491), 12, 204, 190, 20, this);
            this._tfDayNum = ObjCreate.createTextField(Language.getString(44492), 12, 228, 190, 20, this);
            this._bgLong = new Object /* flash.display.Bitmap */();
            ObjCreate.setObjAttri(this._bgLong, 3, 268, -1, -1, this);
            LoaderHelp.addResCallBack(ResFileConst.areanCrossMain, this.onResCompl);
            this._btnJoin = ObjCreate.createGLoadedButton(ResFileConst.GangFightsJoin, 46, 260, 102, 88, this);
            this._btnJoin.addEventListener(flash.events.MouseEvent.CLICK, this.onClickJoin);
            this._tfTimeView = new SecTimerView();
            ObjCreate.setObjAttri(this._tfTimeView, 35, 362, -1, -1, this);
            this._tfTimeView.setParse(Language.getString(44493));
            ObjCreate.createBg(5, 388, 180, 2, this, "SplitLine");
            this._tfMyBeans = ObjCreate.createTextField(Language.getStringByParam(44494, 0), 12, 398, 120, 20, this, GlobalStyle.textFormat6);
            this._tfLastBeans = ObjCreate.createTextField(Language.getStringByParam(44495, 0), 12, 420, 140, 20, this);
            this._btnBeansDetail = ObjCreate.createGButton(Language.getString(44587), 105, 391, 49, 28, this, "LinkButton");
            this._btnBeansDetail.addEventListener(flash.events.MouseEvent.CLICK, this.onClickBeansDetail);
            this._btnExchangeBeans = ObjCreate.createGButton(Language.getString(44496), 143, 391, 49, 28, this, "LinkButton");
            this._btnExchangeBeans.addEventListener(flash.events.MouseEvent.CLICK, this.onClickExchangesBeans);
            this._tfMyMerit = ObjCreate.createTextField(Language.getStringByParam(44497, 0), 12, 441, 120, 20, this, GlobalStyle.textFormat6);
            this._tfLastMerit = ObjCreate.createTextField(Language.getStringByParam(44498, 0), 12, 462, 140, 20, this);
            this._btnMeritDetail = ObjCreate.createGButton(Language.getString(44587), 105, 433, 49, 28, this, "LinkButton");
            this._btnMeritDetail.addEventListener(flash.events.MouseEvent.CLICK, this.onClickMeritDetail);
            this._btnExchangeBeansMerit = ObjCreate.createGButton(Language.getString(44496), 143, 433, 49, 28, this, "LinkButton");
            this._btnExchangeBeansMerit.addEventListener(flash.events.MouseEvent.CLICK, this.onClickExchangesBeansMerit);
            return;
        }

        /* internal  */onClickBeansDetail(arg1: Object /* flash.events.MouseEvent */): void
        {
            GangFightsMagicStoneWindow.instance.show();
            return;
        }

        /* internal  */onClickMeritDetail(arg1: Object /* flash.events.MouseEvent */): void
        {
            GangFightsMeritWindow.instance.show();
            return;
        }

        /* internal  */onClickExchangesBeans(arg1: Object /* flash.events.MouseEvent */): void
        {
            AIManager.onAutoPathAIControl(Cache.instance.scene.getNpcByEffect(ENpcEffect._ENpcEffectMoshiExchange));
            return;
        }

        /* internal  */onClickExchangesBeansMerit(arg1: Object /* flash.events.MouseEvent */): void
        {
            AIManager.onAutoPathAIControl(Cache.instance.scene.getNpcByEffect(ENpcEffect._ENpcEffectMeritExchange));
            return;
        }

        /* internal  */createRightPart(): void
        {
            var loc1=new Object /* flash.display.Sprite */();
            loc1.x = 196;
            loc1.mouseEnabled = false;
            this.addChild(loc1);
            ObjCreate.createSpBannerAndBg(0, 0, 607, 449, "", loc1);
            var loc2=new Vector.<TitleItem>();
            loc2.push(new TitleItem(Language.getString(44468), 180));
            loc2.push(new TitleItem(Language.getString(44470), 60));
            loc2.push(new TitleItem("", 45));
            loc2.push(new TitleItem(Language.getString(44468), 180));
            loc2.push(new TitleItem(Language.getString(44470), 60));
            loc2.push(new TitleItem(Language.getString(44501), 80));
            var loc3=ObjTeamCreate.createTitles(loc2);
            ObjCreate.setObjAttri(loc3, 0, 7, -1, -1, loc1);
            this._tfNoRecord = ObjCreate.createTextField(Language.getString(44502), 240, 200, 200, 20, loc1, GlobalStyle.textFormat6);
            this._tfNoRecord.visible = true;
            this._battlePanel = new TilePanel();
            this._battlePanel.setSize(606, 420);
            this._battlePanel.rowHeight = 42;
            this._battlePanel.columnWidth = 606;
            this._battlePanel.setStyle("cellRenderer", GangFightsBattleCellRenderer);
            this._battlePanel.x = 0;
            this._battlePanel.y = 30;
            this._battlePanel.visible = false;
            loc1.addChild(this._battlePanel);
            this._btnRefresh = ObjCreate.createGButton(Language.getString(44503), 275, 457, 60, 22, loc1);
            this._btnRefresh.addEventListener(flash.events.MouseEvent.CLICK, this.onClickRefresh);
            this.updateLastMoney();
            return;
        }

        /* internal  */onResCompl(): void
        {
            this._bgLong.bitmapData = GlobalClass.getBitmapData(ImagesConst.ArenaCrossBg);
            return;
        }

        /* internal  */onClickAddTeam(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GangFightsChangeToTab, 1));
            return;
        }

        /* internal  */onClickJoin(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (!Cache.instance.gangFights.isHasTeam()) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GangFightsTipAddTeam));
                return;
            }
            if (this._btnJoin.styleName != ResFileConst.GangFightsJoin) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GangFightsCancelJoin));
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GangFightsJoin));
            }
            return;
        }

        /* internal  */onClickRefresh(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GangFightsGetBattles));
            return;
        }

        public updateMyInfo(arg1: SGangFightsMyInfo): void
        {
            this._info = arg1;
            var loc1=0;
            var loc2=arg1.teamWinNum + arg1.teamLoseNum;
            if (loc2 > 0) 
            {
                loc1 = arg1.teamWinNum * 100 / loc2;
            }
            ObjTeamCreate.setTextFieldKeyValue(this._tfName, Language.getString(44481), arg1.teamName, "", "");
            ObjTeamCreate.setTextFieldKeyValue(this._tfScore, Language.getString(44482), arg1.teamMark.toString(), "", "#FF7902");
            ObjTeamCreate.setTextFieldKeyValue(this._tfRank, Language.getString(44483), arg1.teamRank.toString(), "", "#FF7902");
            ObjTeamCreate.setTextFieldKeyValue(this._tfWin, Language.getString(44484), arg1.teamWinNum.toString(), "", "#FFFFFF");
            ObjTeamCreate.setTextFieldKeyValue(this._tfLose, Language.getString(44485), arg1.teamLoseNum.toString(), "", "#FFFFFF");
            ObjTeamCreate.setTextFieldKeyValue(this._tfWinPer, Language.getString(44486), loc1 + "%", "", "#FFFFFF");
            ObjTeamCreate.setTextFieldKeyValue(this._tfTotalNum, Language.getString(44487), loc2.toString(), "", "#FFFFFF");
            ObjTeamCreate.setTextFieldKeyValue(this._tfSelfName, Language.getString(44481), Cache.instance.role.entityInfo.name, "", "");
            ObjTeamCreate.setTextFieldKeyValue(this._tfSelfScore, Language.getString(44482), arg1.mark.toString(), "", "#FF7902");
            ObjTeamCreate.setTextFieldKeyValue(this._tfTodayNum, Language.getString(44491), arg1.todayNum.toString(), "", "#FFFFFF");
            var loc3=10 - arg1.dayNum;
            var loc4=Language.getStringByParam(44492, arg1.dayNum.toString());
            if (loc3 > 0) 
            {
                loc4 = loc4 + Language.getStringByParam(44591, loc3.toString());
            }
            this._tfDayNum.htmlText = loc4;
            var loc5=!(arg1.teamId == 0);
            this._spTeam.visible = loc5;
            this._spNoTeam.visible = !loc5;
            if (loc5) 
            {
                if (this._lineBox) 
                {
                    this._lineBox.dispose();
                }
            }
            else 
            {
                this.lineBox.updateLine(192, 123, [16711680, 16776960]);
                this.addChild(this.lineBox);
            }
            this.updateLastMoney();
            return;
        }

        public updateMyInfoEx(arg1: SGangFightsMyInfoEx): void
        {
            this._infoEx = arg1;
            this.updateLastMoney();
            return;
        }

        public updateAccount(): void
        {
            this.updateLastMoney();
            return;
        }

        public updateBattles(arg1: SGangFightsBattles): void
        {
            var loc1=arg1 && arg1.battles.length;
            this._battlePanel.visible = loc1;
            this._tfNoRecord.visible = !loc1;
            this._battlePanel.dataProvider = new DataProvider(arg1.battles);
            this._battlePanel.drawNow();
            return;
        }

        public updateSignUpState(arg1: SGangFightsSignUp): void
        {
            if (arg1.isCancel) 
            {
                this._btnJoin.styleName = ResFileConst.GangFightsJoin;
            }
            else 
            {
                this._btnJoin.styleName = ResFileConst.GangFightsCancel;
            }
            return;
        }

        public updateMoeny(): void
        {
            this._tfMyBeans.text = Language.getString(380005) + Cache.instance.role.money.magicStone;
            this._tfMyMerit.text = Language.getString(380006) + Cache.instance.role.money.merit;
            return;
        }

        public reset(): void
        {
            this._btnJoin.styleName = ResFileConst.GangFightsJoin;
            return;
        }

        public get lineBox(): LineBox
        {
            if (!this._lineBox) 
            {
                this._lineBox = EffectManager.getLineBox(192, 123);
                this._lineBox.x = 1;
                this._lineBox.y = 1;
            }
            return this._lineBox;
        }

        /* internal */ /* var */_btnBeansDetail: GButton;

        /* internal */ /* var */_btnExchangeBeans: GButton;

        /* internal */ /* var */_tfMyMerit: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfLastMerit: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnMeritDetail: GButton;

        /* internal */ /* var */_tfLose: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfNoRecord: Object /* flash.text.TextField */;

        /* internal */ /* var */_battlePanel: TilePanel;

        /* internal */ /* var */_btnRefresh: GButton;

        /* internal */ /* var */_info: SGangFightsMyInfo;

        /* internal */ /* var */_infoEx: SGangFightsMyInfoEx;

        /* internal */ /* var */_btnExchangeBeansMerit: GButton;

        /* internal */ /* var */_spTeam: Object /* flash.display.Sprite */;

        /* internal */ /* var */_tfName: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfScore: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfRank: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfWin: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfWinPer: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfTotalNum: Object /* flash.text.TextField */;

        /* internal */ /* var */_spNoTeam: Object /* flash.display.Sprite */;

        /* internal */ /* var */_lineBox: LineBox;

        /* internal */ /* var */_btnAddTeam: GButton;

        /* internal */ /* var */_tfSelfName: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfSelfScore: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfTodayNum: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfLastBeans: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfDayNum: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfNeedBattleNum: Object /* flash.text.TextField */;

        /* internal */ /* var */_bgLong: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_btnJoin: GLoadedButton;

        /* internal */ /* var */_tfTimeView: SecTimerView;

        /* internal */ /* var */_tfMyBeans: Object /* flash.text.TextField */;
    }
